﻿using ProsonUser.DomainQuestion;
using ProsonUser.QuestionDTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Application.Services;
using Microsoft.AspNetCore.Mvc;

using ProsonUser.DomainOrderInfo;
using ProsonUser.ProsonOrderDTO;


namespace ProsonUser.ProsonQuestion
{
    public class PQuestion : ApplicationService, IQuestion
    {
        private readonly IRepository<Question, int> _question;
        public PQuestion(IRepository<Question, int> question)
        {
            _question = question;

        }
        [HttpPost,Route("AddQuery")]
        public async Task<int> AddQuery(QuestionCreateDTO dto)
        {   
            dto.CreateTime = DateTime.Now;
            dto.pid = 0;
            var query = await _question.InsertAsync(ObjectMapper.Map<QuestionCreateDTO, Question>(dto));
            return 1;
        }
        //课程列表
        [HttpGet,Route("QuestionList")]
        public List<Question> QuestionList(string qName)
        {
            var query =  _question.Where(s=>s.pid==0).ToList();
            
            if (qName != null)
            {
                query = query.Where(s => s.QName.Contains(qName)).ToList();
            }
            return query;
        }
        [HttpGet, Route("QuestionFind")]
        public  List<Question> QuestionFind(int id)
        {
            var lst = _question.Where(s => s.Id.Equals(id)).FirstOrDefault();

            var query = _question.Where(s=>s.pid==lst.Id).ToList();
            return query;
        }
        [HttpDelete,Route("RemoveQuestion")]
        public async Task<int> RemoveQuestion(int id)
        {
            var query = _question.Where(s => s.Id.Equals(id)).FirstOrDefault();
            await _question.DeleteAsync(query);
            return 1;
        }
        [HttpGet,Route("QuestionFindOne")]
        public async Task<Question> QuestionFindOne(int id)
        {
            Question question =await _question.FindAsync(id);
            return question;
        }
        [HttpPost,Route("UpdateQuestion")]
        public async Task<int> UpdateQuestion(QusetionDTO dto)
        {
            Question question =await _question.FindAsync(dto.Id);
            question.QName = dto.QName;
            return 1;

        }



    }
}
